<?php
/**
 * 快递员S端增值业务( value added service)
 */

namespace soa\vas;

use soa\client;

class courier_vas extends client
{
    //服务地址
    public $service_url = 'http://express.core.kuaidihelp.com/';
    //服务名称
    public $service_name = 'kuaidihelp_express';


    /**
     * 拉去增值业务的列表
     * @param $pageNumber
     * @param $pageSize
     * @param $cmId
     * @return bool
     */
    public function getList($pageNumber, $pageSize, $cmId)
    {
        return $this->get('v1/courier_vas/getList',
            array('pageNumber' => $pageNumber, 'pageSize' => $pageSize, 'cmId' => $cmId));
    }

    public function getVasInfo($courierId)
    {
        return $this->get('v1/courier_vas/getVasInfo', array('courierId' => $courierId));
    }

    /**
     * 快递员添加增值列表
     * @param array $arr
     * @return bool
     */
    public function add(array $arr)
    {
        if(empty($arr)) {
            return false;
        }

        $ret = $this->get('v1/courier_vas/add', ['arr' => $arr]);
        return $ret;
    }

    /**
     * 增值业务详情编辑
     * @param array $data
     * @return bool
     */
    public function modify($data)
    {
        return $this->get('v1/courier_vas/modify', array('data' => $data));
    }

    /**
     * 增值业务删除
     * @param $id
     * @return bool
     */
    public function del($id, $courierId)
    {
        return $this->get('v1/courier_vas/del', array('id' => $id, 'courierId' => $courierId));
    }

    public function search()
    {
        //todo
    }

    public function callback($courierId, $uuid)
    {
        return $this->get('v1/courier_vas/callback', ['courierId' => $courierId, 'uuid' => $uuid]);
    }

    /**
     * 财来网开关
     * @param $courierId
     * @return bool
     */
    public function open($courierId, $switch)
    {
        return $this->get('v1/courier_vas/open', ['courierId' => $courierId, 'switch' => $switch]);
    }

    /**
     * 获取签收单的GPS数据
     * @param array $waybillNo 单号
     * @param string $brand
     * @return array
     */
    public function getGPS(array $waybillNo, $brand='sto')
    {
        if($brand =='sto')
            return $this->get('v1/parter/sto/getGPS', ['waybillNo' => $waybillNo]);
        elseif($brand=='qf')
            return '';
        elseif($brand=='zt')
            return '';
        else
            return '';
    }

    /**
     * 获取快递员推广连接key
     * @param $ref
     * @param $act
     * @param $courierId
     * @param $value
     * @return bool
     */
    public function handle($ref, $act, $courierId, $value)
    {
        if($act=='get')
            return $this->get('v1/courier_vas/getKey', array('ref' => $ref, 'courierId' => $courierId));
        elseif($act=='add')
            return $this->get('v1/courier_vas/addKey', array('ref' => $ref, 'courierId' => $courierId, 'value'=> $value));
        elseif($act =='del')
            return $this->get('v1/courier_vas/delKey', array('ref' => $ref, 'courierId' => $courierId));
    }
}